package com.vrv.common;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.vrv.netmgr.R;

public class UpdateDialog implements OnClickListener{
	//
	private Dialog updateDialog;
	private Button updateLeft, updateRight;
	//
	public UpdateDialog(Context context){
		//
		updateDialog = new Dialog(context);
		updateDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        //
        Window window = updateDialog.getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = 200;
        window.setAttributes(layoutParams);
        //
        View layout = LayoutInflater.from(context).inflate(R.layout.view_update_dialog, null);
        updateDialog.show();
        //
        updateLeft = (Button) layout.findViewById(R.id.update_left);
        updateRight = (Button) layout.findViewById(R.id.update_right);
      //为按钮设置事件监听
        updateLeft.setOnClickListener(this);
        updateRight.setOnClickListener(this);
		updateDialog.setContentView(layout);
	}
	// 事件传递接口
	public interface MyDialogInt {
		public void onClick(View view);
	}
	MyDialogInt LeftcallBack = null;
	MyDialogInt RightcallBack = null;
	//定义一些操作dialog的方法
	public void dismiss() {
		updateDialog.dismiss();
	}
	public void cancel(){
		updateDialog.cancel();
	}
	public boolean isShowing() {
		return updateDialog.isShowing();
	}
	public void onClick(View view) {
		if (view == updateLeft) {
			LeftcallBack.onClick(view);
		} else if (view == updateRight) {
			RightcallBack.onClick(view);
		}
	}
	// 设置左按钮
	public void setLeftButton(String value, MyDialogInt iBack) {
		if (value == null || value.equals("")) {
			return;
		}
		updateLeft.setVisibility(View.VISIBLE);
		updateLeft.setText(value);
		LeftcallBack = iBack;
	}
	// 设置右按钮
	public void setRightButton(String value, MyDialogInt iBack) {
		if (value == null || value.equals("")) {
			return;
		}
		updateRight.setVisibility(View.VISIBLE);
		updateRight.setText(value);
		RightcallBack = iBack;
	}
}
